<docs>
</docs>
<template>
  <div v-show="hasInitEvent" class="selects" @click.stop>
    <div class="search">
      <input type="text" placeholder="请输入职位关键字" v-model="gwmc">
      <button class="weui-btn_primary" @click.prevent="getPosition(gwmc)">搜索</button>
      <button class="weui-btn_default" @click.prevent="backBase()">取消</button>
    </div>
    <div class="position">
      <ul>
        <li
          v-for="(item, index) in position"
          :key="index"
          @click="choose(item.gwmc,item.gwbh, item)"
          :gwbh="item.gwbh"
        >{{item.gwmc}}</li>
        <li class="no_data" v-show="!isFirst && position.length === 0">无匹配结果，请重新输入</li>
      </ul>
    </div>
    <p class="list_num" v-show="!isFirst">共{{position.length}}条结果</p>
  </div>
</template>
<script>
import $ from "@/common/js/axios";

export default {
  props: {
    hasInitEvent: {
      type: Boolean,
      default: false
    },
    gsgw:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      position: [],
      gwmc: "",
      isFirst: true
    };
  },
  watch:{
    'hasInitEvent'(val){
      if(val){
        this.getPosition();
      }
    }
  },
  methods: {
    backBase() {
      this.$emit("update:hasInitEvent", false);
    },
    getPosition(gwmc) {
      let url = this.gsgw? "/dwgl/tdgwlbCx" : "/dmbgl/tsgwCx"
      $.get(url, { params: { gwmc, pageSize: 500 } }).then(res => {
        const data = res.returnData;
        if (+data.executeResult == 1) {
          this.position = data.tsgwxx;
          this.isFirst = false;
        }else{
          this.isFirst = false;
          this.position = [];
        }
      });
    },
    // 点击职位获取职位名称
    choose(name, gwbh, item) {
      this.$emit("update:labelName", name);
      this.gsgw?this.$emit("update:item", item):"";
      this.$emit("update:gwbh", gwbh);
      this.$emit("update:hasInitEvent", false);
      this.gwmc = '';
      this.postion = [];
      this.isFirst = true;
    }
  }
};
</script>
<style scoped lang="scss">
@import "~common/scss/var.scss";
.weui-label {
  @include label;
}

.selects {
  position: fixed;
  top: 114px;
  left: 0;
  background-color: #fff;
  z-index: 3;
  width: 100%;
  height: 100%;
}
.search {
  display: flex;
  margin: 20px 0;
  input {
    width: 60%;
    margin: 0 2% 0 4%;
    border: 1px solid #ccc;
    border-radius: 30px;
    height: 60px;
    line-height: 60px;
    padding-left: 20px;
  }
  button {
    width: 15%;
    height: 60px;
    line-height: 60px;
    font-size: 30px;
    border-radius: 5px;
    margin: 0 5px;
    border: 1px solid rgba(0, 0, 0, 0.2);
  }
  .weui-btn_primary {
    color: #fff;
    background-color:#06A8F6;
  }
  .weui-btn_default {
    margin-top: 0px;
  }
}
.position {
  max-height: 800px;
  overflow: scroll;
  ul {
    margin-bottom: 30px;
    width: 90%;
    margin: 0 auto;
  }
  li {
    height: 80px;
    line-height: 80px;
    font-size: 30px;
    color: $color-text-primary;
    text-align: center;
  }
  li:nth-of-type(odd) {
    background-color: rgba(#f7f7f7, 0.7);
  }
  li:nth-of-type(even) {
    background-color: rgba(#e0eee0, 0.7);
  }
}
.btn {
  width: 100%;
  display: flex;
  button {
    width: 40%;
    margin-top: 0;
  }
}
.list_num {
  text-align: center;
  font-size: $font-size-small;
  padding: $padding-base;
  color: $color-text-label;
}
</style>
